package com.javabi.htmlbuilder.html.element.list;

import java.util.ArrayList;
import java.util.List;

import com.javabi.htmlbuilder.html.HTMLBuilder;
import com.javabi.htmlbuilder.html.HTMLElement;
import com.javabi.htmlbuilder.html.HTMLElementName;

/**
 * An Ordered List
 */
public class OrderedList extends HTMLElement<OrderedList> {

	/** The item list. */
	private final List<ListItem> itemList = new ArrayList<ListItem>();

	/**
	 * Returns a new list item.
	 * @return a new list item.
	 */
	public ListItem li() {
		ListItem item = new ListItem();
		itemList.add(item);
		return item;
	}

	/**
	 * Returns a new list item.
	 * @return a new list item.
	 */
	public ListItem item() {
		return li();
	}

	/**
	 * Returns the element name.
	 * @return the element name.
	 */
	public HTMLElementName getElementName() {
		return HTMLElementName.ORDERED_LIST;
	}

	/**
	 * Append this to the given html builder.
	 * @param html the html builder.
	 * @return the html builder.
	 */
	public HTMLBuilder appendTo(HTMLBuilder html) {
		if (!itemList.isEmpty()) {
			html.open(this, true);
			appendInlineStyleAttributesTo(html);
			for (ListItem item : itemList) {
				item.appendTo(html);
			}
			html.close(this);
		}
		return html;
	}

	/**
	 * Returns true to format this element.
	 * @return true to format this element.
	 */
	public boolean format() {
		return true;
	}

}
